package com.ybkj.o2o.mc.service.impl;


import com.ybkj.o2o.mc.entity.PassengerConcats;
import com.ybkj.o2o.mc.mapper.PassengerConcatsMapper;
import com.ybkj.o2o.mc.service.PassengerConcatsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shine on 15/8/19.
 */
@Service
public class DefaultPassengerConcatsService implements PassengerConcatsService {

  @Autowired
  private PassengerConcatsMapper passengerConcatsMapper;

  @Override
  public boolean exists(String phone, Long passengerId) {

    PassengerConcats concats = passengerConcatsMapper.selectByPhoneAndPassenger(phone, passengerId);

    return concats != null;
  }

  @Override
  public int insert(PassengerConcats concats) {
    concats.setCreated(new Date());
    concats.setUpdated(new Date());
    return passengerConcatsMapper.insert(concats);
  }


  @Override
  public PassengerConcats findByConcatsAndPassenger(Long concatsId, Long passengerId) {

    return passengerConcatsMapper.selectByConcatsAndPassenger(concatsId, passengerId);
  }

  @Override
  public int deleteByIdAndPassengerId(Long concatsId, Long passengerId) {

    return passengerConcatsMapper.deleteByIdAndPassenger(concatsId, passengerId);
  }

  @Override
  public int update(PassengerConcats concats) {

    concats.setUpdated(new Date());
    return passengerConcatsMapper.updateByPrimaryKey(concats);
  }

  @Override
  public List<PassengerConcats> findByPassengerId(Long passengerId) {

    return passengerConcatsMapper.selectByPassenger(passengerId);
  }

  @Override
  public List<PassengerConcats> findAll(Long passengerId, int offset, int rows) {

    return passengerConcatsMapper.selectByPassengerForPage(passengerId, offset, rows);
  }

  @Override
  public long count(Long passengerId) {

    return passengerConcatsMapper.countByPassenger(passengerId);
  }

  @Override
  public int deleteByPassenger(Long passengerId) {

    return passengerConcatsMapper.deleteByPassenger(passengerId);
  }

  @Override
  public int deleteByPassengers(List<Long> passengers) {

    return passengerConcatsMapper.deleteByPassengers(passengers);
  }
}
